package com.example;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableEurekaClient  //开启注册中心客户端
@EnableCircuitBreaker  //开启服务熔断器
@EnableFeignClients  //开启声明式接口消费 ribbon+hystrix降级
@EnableHystrix
@EnableHystrixDashboard  //服务仪表盘监控
public class HystrixApplication {

    public static void main(String[] args) {
        SpringApplication.run(HystrixApplication.class,args);
    }

//    /**
//     * 解决访问http://192.168.129.1:8083/actuator/hystrix.stream监控404问题
//     * @return
//     */
//    @Bean
//    public ServletRegistrationBean hystrixServlet(){
//
//        //创建仪表盘监控Servlet
//        HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
//        //创建servlet
//        ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean =
//                new ServletRegistrationBean<>(hystrixMetricsStreamServlet);
//        //添加映射
//        servletRegistrationBean.addUrlMappings("/**");
//        servletRegistrationBean.setName("hystrixServlet");
//
//        return servletRegistrationBean;
//    }
}
